package com.example.voltorb.flip;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;


public class OnTileClickListener implements OnItemClickListener {
	
	Context c;
	
	public OnTileClickListener(Context context) {
		super();
		this.c = context;
	}

	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Game g = ((MainActivity) this.c).getGame();
		if (g.isMarkModeOn()) {
			g.getTiles().get(position).toggleMarking();
		} else {
			g.turnTile(position);
		}
		((TileAdapter) parent.getAdapter()).notifyDataSetChanged();
		
//		@SuppressWarnings("unchecked")
//		ArrayAdapter<Tile> a = (ArrayAdapter<Tile>) parent.getAdapter();
//		Tile t = a.getItem(position);
//		t.turn();
//		a.notifyDataSetChanged();
//		
//		MainActivity main = (MainActivity) this.c;
//		if (t instanceof VoltorbTile) {
//			// Get instance of Vibrator from current Context
//    		Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
//    		// Vibrate for one second
//    		vibe.vibrate(1000);
//    		
//    		main.showEndingDialog(false);
//		} else if (t instanceof CoinTile) {
//			main.addCoins(((CoinTile) t).getCoinAmount());
//		}
//		
//		// Check for game ending
//		if (main.getGame().isCleared()) {
//			main.showEndingDialog(true);
//		}
	}
	
}
